# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class world_year_book(models.Model):

    _name = "yearbook.world_year_book"
    _description = "世界年鉴"
    _table = "yearbook_world_year_book"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Char(string="清单名称",translate = 0)
    country_id = fields.Many2one(string="国家",comodel_name = 'res.country',default = lambda self:self.env['res.country'].search([('code','=','CN')]),translate = 0)
    industry_category = fields.Many2one(string="所属行业",comodel_name = 'setcent.industry_category',translate = 0)
    indicator_category_id = fields.Many2one(string="指标分类",comodel_name = 'datcent.data_category',related = 'indicator_id.indicator_category_id',readonly = 1,store = 1,translate = 0)
    indicator_id = fields.Many2one(string="指标名称",comodel_name = 'datcent.data_indicator',translate = 0)
    uom_id = fields.Many2one(string="计量单位",comodel_name = 'uom.uom',related = 'indicator_id.uom_id',store = 1,translate = 0)
    datetime = fields.Date(string="日期时间",translate = 0)
    data_period = fields.Selection(string="数据周期",selection = [('1', '年度'), ('2', '季度'), ('3', '月度'), ('4', '周度'), ('5', '日度')],default='1',translate = 0)
    value_floa = fields.Float(string="数字指标值",translate = 0)
    value_char = fields.Char(string="描述指标值",translate = 0)
    data_source = fields.Many2one(string="数据来源",comodel_name = 'datcent.data_source',translate = 0)
    memo = fields.Text(string="指标说明",translate = 0)
    active = fields.Boolean(string="归档",default = 1,translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
